package com.lzx.adx.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.lzs.adx.commmon.service.impl.CrudServiceImpl;
import com.lzx.adx.report.dao.EleUnionOrderDao;
import com.lzx.adx.report.dto.EleUnionOrderDTO;
import com.lzx.adx.report.entity.EleUnionOrderEntity;
import com.lzx.adx.report.service.EleUnionOrderService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class EleUnionOrderServiceImpl extends CrudServiceImpl<EleUnionOrderDao, EleUnionOrderEntity, EleUnionOrderDTO> implements EleUnionOrderService {

    @Autowired
    private  EleUnionOrderDao eleUnionOrderDao;

    @Override
    public QueryWrapper<EleUnionOrderEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<EleUnionOrderEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public void saveAndUpdateData(List<EleUnionOrderEntity> data) {
        for (EleUnionOrderEntity datum : data) {
            EleUnionOrderEntity eleUnionOrderEntity = eleUnionOrderDao.selectById(datum.getId());
            if(ObjectUtils.isEmpty(eleUnionOrderEntity)){
                eleUnionOrderDao.insert(eleUnionOrderEntity);
            }else{
                eleUnionOrderDao.updateById(eleUnionOrderEntity);
            }
        }

    }
}